package com.sajus.billing.client.util;


/**
 * Utility class to log performance and entry exit points
 * 
 * @author nicolara
 *
 */
public class DebugTimeCheckpoint {

	private String topic;
	private long lastTimeInMS = System.currentTimeMillis();
	private long startTime = 0;

	public void report(String msg) {
		long time = System.currentTimeMillis();
		String str ;
		if (msg != null && msg.length() > 0 ) {
			str = this.topic + " [" + msg + "]: IntervalTime=" +  (time-lastTimeInMS) + "ms : ElapsedTime=" + (time-startTime) + "ms";
		} else {
			str = this.topic + " : IntervalTime=" +  (time-lastTimeInMS) + "ms : ElapsedTime=" + (time-startTime) + "ms";
		}
		
		lastTimeInMS = time;
	}

	public DebugTimeCheckpoint(String methodName, boolean performanceTest) {
		this.topic = "[Method Name: " + methodName + "]" + " Performance Testing " ;
		startTime = System.currentTimeMillis();
	}

	public DebugTimeCheckpoint(String topic) {
		super();
		this.topic = topic;
		startTime = System.currentTimeMillis();
	}

	public void done() {
		long time = System.currentTimeMillis();
		String str = this.topic + " : OverallTime=" +  (time-startTime) + "ms";
	}

	public void done(String msg) {
		long time = System.currentTimeMillis();
		String str = "[" + msg + ": ]" +  this.topic + " : OverallTime="  +  (time-startTime) + "ms";
	}

}
